Practice
Classwork
Create a project, and in it a class with a main.
We will be using the Scanner class to read from the user. At the top of your
main class, after the package statement, paste
import java.util.Scanner;
As the first line inside your main method, paste
Scanner scan = new Scanner(System.in);
In order to read from the user, we use the Scanner like this:
int x = scan.nextInt(); // read an int
double d = scan.nextDouble(); // read a double
String s = scan.next(); // read a String
Part A
☑ In your main,
We will use loops to do a simple menu. The options are:
0. Quit
1. Print stars
2. Guess Number
3. Build an Owl
So we want to repeatedly show these options, get input from the user, and act on
their choice, until they choose 0 to quit.
☑ If they enter 1, ask them for a number, and use a for loop to print that many stars in a row (on the same line).
☑ If they enter 2, choose a number and have the user guess until they get it right. For each incorrect guess, tell them whether they are too high or too low.
Part B
Create a class representing the type of animal you had them choose, give it a name and one other instance variable, and a behavior.
☑ If they enter 3, choose the name of a type of animal, and make them guess until they correctly guess the type of animal.
Part C
Back in main, if they choose 3, show them a submenu with the options
0. Return to Main Menu
1. Create a new Owl
2. Name the Owl
3. Feed the Owl
4. Release the Owl
create an instance of your class, let them name the animal, and then have it do its behavior.